package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.Throw;
import com.cq.hd.member.api.TbBusinessAgentApi;
import com.cq.hd.member.api.dto.AgentPageDto;
import com.cq.hd.member.api.dto.MyBusinessPageDto;
import com.cq.hd.member.api.vo.AgentPageVo;
import com.cq.hd.member.api.vo.MyBusinessPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商家经纪人关联表 前端控制器
 * </p>
 *
 * @author mYunYu
 * @since 2023-11-21
 */
@Api(tags = "经纪人相关接口")
@Slf4j
@RestController
@RequestMapping("/agent")
public class TbBusinessAgentController {

    private TbBusinessAgentApi businessAgentApi;

    @Autowired
    public void setBusinessAgentApi(TbBusinessAgentApi businessAgentApi) {
        this.businessAgentApi = businessAgentApi;
    }

    @ApiOperation(value = "经纪人列表")
    @ApiResponse(response = AgentPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("agent:agent:list")
    @RequiresPermissionsDesc(menu = {"经纪人管理", "经纪人管理"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<AgentPageVo>> pageAgent(AgentPageDto agentPageDto) {
        return businessAgentApi.pageAgent(agentPageDto);
    }

    @ApiOperation(value = "经纪人关联商家列表")
    @ApiResponse(response = AgentPageVo.class, code = 200, message = "接口返回对象参数")
//    @RequiresPermissions("agent:agent:list")
    @RequiresPermissionsDesc(menu = {"经纪人管理", "经纪人管理"}, button = "查询")
    @GetMapping("/relatedBusiness")
    public Result<Page<MyBusinessPageVo>> relatedBusiness(MyBusinessPageDto myBusinessPageDto) {
        Long userId = myBusinessPageDto.getUserId();
        if (userId == null || userId <= 0) {
            Throw.isBusinessException("经纪人id不能为空");
        }
        return businessAgentApi.pageMyBusiness(myBusinessPageDto);
    }
}
